package com.example.recordingpen_datacollection.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.recordingpen_datacollection.Utils.String.StringValidator;
import com.example.recordingpen_datacollection.config.AOP.annotation.PreventRepeatSubmit;
import com.example.recordingpen_datacollection.entity.Device;
import com.example.recordingpen_datacollection.result.RLIST;
import com.example.recordingpen_datacollection.service.DeviceService;
import com.example.recordingpen_datacollection.service.LoginService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xg
 * @since 2023-11-14
 */
@RestController
@RequestMapping("/device")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;



    @ApiOperation(value = "添加设备信息")
    @PreventRepeatSubmit()
    @PostMapping("/setDevice")
    public RLIST setDevice(@RequestBody Device device){
        String phone = device.getPhone();
        boolean phoneNumber = StringValidator.isValidPhoneNumber(phone);
        if(!phoneNumber){
            return RLIST.error().message("手机号异常");
        }

        boolean save = deviceService.devMessageRecord(device);
        if(save){
            return RLIST.ok();
        } else {
            return RLIST.error();
        }

    }

}

